package cn.b.sky.mes.hr.controller;

import java.util.List;
import java.util.Map;

import cn.b.sky.mes.hr.model.Performance;
import cn.b.sky.mes.hr.model.ShiftingPermission;
import cn.b.sky.mes.hr.model.condition.PerformanceCondition;
import cn.b.sky.mes.hr.service.PerformanceService;
import cn.b.sky.mes.hr.service.ShiftingPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.b.sky.user.SecurityContextUtil;
import cn.b.sky.user.controller.SecurityController;

@Controller
@RequestMapping(value = "/timeBoard/*")
public class TimeBoardController extends SecurityController {

  @Autowired
  private ShiftingPermissionService shiftingPermissionService;

  @Autowired
  private PerformanceService performanceService;

  @RequestMapping("page")
  public String shiftingListPage(String navTabId, Model model) {
    model.addAttribute(NAVTABID, navTabId);
    model.addAttribute("permissions", shiftingPermissionService.getPermissionsByUser(this.getSiteCode(),
        SecurityContextUtil.getCurrentUserName(), null));
    return "hr/performance/timeBoard";
  }

  @RequestMapping("getPerformances")
  @ResponseBody
  public List<Map<String, Object>> getPerformances(PerformanceCondition condition) {
    condition.setSiteCode(getSiteCode());
    List<ShiftingPermission> permissions = shiftingPermissionService.getPermissionsByUser(this.getSiteCode(),
        SecurityContextUtil.getCurrentUserName(), null);
    condition.setPermission(permissions);
    return performanceService.selectAllPerformanceReportMapList(condition);
  }

  @RequestMapping("getPerformanceBypersonnelAndPeriod")
  @ResponseBody
  public List<Performance> getPerformanceBypersonnelAndPeriod(PerformanceCondition condition) {
    if (null == condition.getSiteCode()) {
      condition.setSiteCode(getSiteCode());
    }
    return performanceService.getPerformanceBypersonnelAndPeriod(condition);
  }

}
